#ifndef __ODRIVE_H
#define	__ODRIVE_H

#include "stdint.h"
#include "stm32f4xx.h"
/****************************Controller******************************/
typedef enum
{
	CONTROL_MODE_VOLTAGE_CONTROL     = 0,
	CONTROL_MODE_TORQUE_CONTROL      = 1,
	CONTROL_MODE_VELOCITY_CONTROL    = 2,
	CONTROL_MODE_POSITION_CONTROL    = 3,
} eOdriveCtrlMode;

typedef enum
{
	INPUT_MODE_INACTIVE      = 0,
	INPUT_MODE_PASSTHROUGH   = 1,
	INPUT_MODE_VEL_RAMP      = 2,
	INPUT_MODE_POS_FILTER    = 3,
  INPUT_MODE_MIX_CHANNELS  = 4,
  INPUT_MODE_TRAP_TRAJ     = 5,
  INPUT_MODE_TORQUE_RAMP   = 6,
  INPUT_MODE_MIRROR        = 7,
} eOdriveInputMode;

/*sender:Master*/
#define CMD_ESTOP_MESSAGE           0x02
#define CMD_SET_AXIS_NODE_ID        0x06
#define CMD_SET_AXIS_REQUESTED_STAE 0x07
#define CMD_SET_AXIS_STARTUP_CONFIG 0x08
#define CMD_GET_ENCODER_ESTIMATES   0x09
#define CMD_GET_ENCODER_COUNT       0x0a
#define CMD_SET_CONTROLLER_MODES    0x0b
#define CMD_SET_INPUT_POS           0x0c
#define CMD_SET_INPUT_VEL           0x0d
#define CMD_SET_INPUT_TORQUE        0x0e
#define CMD_SET_VELOCITY_LIMIT      0x0f
#define CMD_START_ANTICOGGING       0x10
#define CMD_SET_TRAJ_VEL_LIMIT      0x11
#define CMD_SET_TRAJ_ACCEL_LIMITS   0x12
#define CMD_SET_TRAJ_INERTIA        0x13
#define CMD_GET_SENSORLESS_ESTIMATES 0x15
#define CMD_REBOOT_ODRIVE           0x16
#define CMD_GET_VBUS_VOLTAGE        0x17
#define CMD_CLEAR_ERRORS            0x18


extern uint8_t my_axis_id;

void Get_Encoder_Estimates(void);

void Set_Controller_Modes(uint16_t axis_node_id,eOdriveCtrlMode ControlMode,eOdriveInputMode InputMode);
void Set_Input_Pos(uint16_t axis_node_id, fp32 pos, int16_t vff , int16_t tff );
void Set_Input_Vel(uint16_t axis_node_id, fp32 Input_Vel, fp32 tff );
void Set_Velocity_Limit(uint16_t axis_node_id, fp32 vel_limit);

void Cmd_to_Odrive(uint16_t axis_node_id, uint8_t cmd_implemented);
void Get_Vbus_Voltage(void);


#endif 



